package com.boco.webmaster.common.taglib;

import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;

import com.boco.common.util.db.DbCollection;

public class DbCollectionReadTag  extends TagSupport {
    private String dboPackageName = "com.boco.webmaster.common.dbmodle";
    private String queryResultName = "queryResult";
    private String dboClassName;
    private String rowIndexName;
    private String dboFieldName;

    public DbCollectionReadTag() {
    }

    public void setDboPackageName(String dboPackageName) {
        this.dboPackageName = dboPackageName;
    }

    public void setDboClassName(String dboClassName) {
        this.dboClassName = dboClassName;
    }

    public void setQueryResultName(String queryResultName) {
        this.queryResultName = queryResultName;
    }

    public void setRowIndexName(String rowIndexName) {
        this.rowIndexName = rowIndexName;
    }

    public void setDboFieldName(String dboFieldName) {
        this.dboFieldName = dboFieldName;
    }

    public String getDboPackageName() {
        return dboPackageName;
    }

    public String getDboClassName() {
        return dboClassName;
    }

    public String getQueryResultName() {
        return queryResultName;
    }

    public String getRowIndexName() {
        return rowIndexName;
    }

    public String getDboFieldName() {
        return dboFieldName;
    }

    public int doStartTag() throws JspException {
        DbCollection queryResult = (DbCollection)pageContext.getRequest().getAttribute(this.queryResultName);
        Integer rowIndex = (Integer)pageContext.findAttribute(this.rowIndexName);

        try {
            Object value = queryResult.getQueryDboField(this.dboPackageName + "." + this.dboClassName,
                rowIndex.intValue(), this.dboFieldName);
            if(value != null){
                pageContext.getOut().write(value.toString());
            }
        } catch (Exception ex) {
            throw new JspException(ex);
        }

        return Tag.SKIP_BODY;
    }
}
